classes = parse_classes(trialClasses);                                                                                                                                                                                                                                                                                                                                                        
hit_step = 0.005;                                                                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                                                                                              
ntrials = length(hit_history);                                                                                                                                                                                                                                                                                                                                                                
                             
last15hit =   hit_history(max(1, ntrials-15):ntrials);                                                                                                                                                                                                                                                                                                                                        
last25hit =   hit_history(max(1, ntrials-25):ntrials);                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                                              
last15cls = class_history(max(1, ntrials-15):ntrials);                                                                                                                                                                                                                                                                                                                                        
last25cls = class_history(max(1, ntrials-25):ntrials);                                                                                                                                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                                                                                                                              
rc = find(classes.side == 'R');                                                                                                                                                                                                                                                                                                                                                               
lc = find(classes.side == 'L');                                                                                                                                                                                                                                                                                                                                                               
left15  = find(ismember(last15cls, lc));                                                                                                                                                                                                                                                                                                                                                      
right15 = find(ismember(last15cls, rc));                                                                                                                                                                                                                                                                                                                                                      
left25  = find(ismember(last25cls, lc));                                                                                                                                                                                                                                                                                                                                                      
right25 = find(ismember(last25cls, rc));                                                                                                                                                                                                                                                                                                                                                      
                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                              
if ntrials > 20,                                                                                                                                                                                                                                                                                                                                                                               
   if LeftProb==1  ||  LeftProb==0,                                                                                                                                                                                                                                                                                                                                                           
       if     ~isempty(right15)  &&  mean(last15hit(right15)) < 0.35,                                                                                                                                                                                                                                                                                                                         
           LeftProb.value = 0;                                                                                                                                                                                                                                                                                                                                                                
       elseif ~isempty(left15)   &&  mean(last15hit(left15))  < 0.35,                                                                                                                                                                                                                                                                                                                         
           LeftProb.value = 1;                                                                                                                                                                                                                                                                                                                                                                
       else                                                                                                                                                                                                                                                                                                                                                                                   
           LeftProb.value = 0.5;                                                                                                                                                                                                                                                                                                                                                              
       end;                                                                                                                                                                                                                                                                                                                                                                                   
   else                                                                                                                                                                                                                                                                                                                                                                                       
       if     ~isempty(right25)  &&  mean(last25hit(right25)) < 0.35,                                                                                                                                                                                                                                                                                                                         
           LeftProb.value = 0;                                                                                                                                                                                                                                                                                                                                                                
       elseif ~isempty(left25)   &&  mean(last25hit(left25))  < 0.35,                                                                                                                                                                                                                                                                                                                         
           LeftProb.value = 1;                                                                                                                                                                                                                                                                                                                                                                
       else                                                                                                                                                                                                                                                                                                                                                                                   
           LeftProb.value = 0.5;                                                                                                                                                                                                                                                                                                                                                              
       end;                                                                                                                                                                                                                                                                                                                                                                                   
   end;                                                                                                                                                                                                                                                                                                                                                                                       
end;                                                                                                                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                              
switch class_history(length(class_history)),                                                                                                                                                                                                                                                                                                                                                  
    case 1,                                                                                                                                                                                                                                                                                                                                                                                   
    case 2,                                                                                                                                                                                                                                                                                                                                                                                   
            sp = adaptive_step(classes.startPosition(2), hit_history(length(hit_history)), 'hit_step', -hit_step, 'stableperf', 0.75, 'mx', 0.50, 'mn', 0.2);                                                                                                                                                                                                                                 
            ep = sp + 0.3;                                                                                                                                                                                                                                                                                                                                                                    
            fprintf(1, 'AdaptingSection: case 2, sp=%.3f, ep=%.3f\n', sp, ep);                                                                                                                                                                                                                                                                                                                
            classes.startPosition(2) = sp; classes.endPosition(2) = ep;                                                                                                                                                                                                                                                                                                                       
    case 3,                                                                                                                                                                                                                                                                                                                                                                                   
    case 4,                                                                                                                                                                                                                                                                                                                                                                                   
            sp = adaptive_step(classes.startPosition(4), hit_history(length(hit_history)), 'hit_step', hit_step, 'stableperf', 0.75, 'mx', 0.80, 'mn', 0.5);                                                                                                                                                                                                                                  
            ep = sp - 0.3;                                                                                                                                                                                                                                                                                                                                                                    
            fprintf(1, 'AdaptingSection: case 2, sp=%.3f, ep=%.3f\n', sp, ep);                                                                                                                                                                                                                                                                                                                
            classes.startPosition(4) = sp; classes.endPosition(4) = ep;                                                                                                                                                                                                                                                                                                                       
    otherwise,                                                                                                                                                                                                                                                                                                                                                                                
        warning('huh???');                                                                                                                                                                                                                                                                                                                                                                    
end;                                                                                                                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                                                                                              
StimulusClassesSection(obj, 'set_classes', classes);                                                                                                                                                                                                                                                                                                                                          
drawnow;                                                                                                                                                                                                                                                                                                                                                                                      

